package com.jrx.anytxn.param.transaction;


import com.alibaba.fastjson.JSON;
import com.jrx.anytxn.common.uitl.StartCommand;
import jrx.batch.common.config.EnableBatchTask;
import org.apache.rocketmq.client.log.ClientLogger;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.util.Arrays;
import java.util.UUID;

@SpringBootApplication(scanBasePackages={"com.jrx.anytxn"})
@EnableFeignClients(basePackages = {"com.jrx.anytxn.feign.gateway.service","com.jrx.anytxn.feign.param.service"})
@EnableBatchTask
@EnableDiscoveryClient
@EnableTransactionManagement
@MapperScan({"com.jrx.anytxn.*.mapper"})
public class AnytxnTransactionParamBatchApplication {

    private static final Logger logger = LoggerFactory.getLogger(AnytxnTransactionParamBatchApplication.class);

    public static void main(String[] args) {
        logger.info("初始启动参数:{}", JSON.toJSONString(args));
        System.out.println("初始启动参数:"+JSON.toJSONString(args));
        String[] newArgs  = Arrays.copyOf(args,args.length+1);
        newArgs[args.length] = "--job.executeUUID="+ UUID.randomUUID().toString().replace("-","");
        newArgs = StartCommand.getStartServerArgs(newArgs);
        logger.info("当前启动参数:{}", JSON.toJSONString(newArgs));
        System.out.println("当前启动参数:"+JSON.toJSONString(args));
        try{
            System.setProperty(ClientLogger.CLIENT_LOG_USESLF4J, "true");
//            SpringApplication.run(AnytxnTransactionParamBatchApplication.class, newArgs);
            SpringApplication springApplication =new SpringApplication(AnytxnTransactionParamBatchApplication.class);
            springApplication.setWebApplicationType(WebApplicationType.NONE);
            springApplication.run(newArgs);
        }catch(Exception e){
            logger.error("异常",e);
            System.exit(0);
        }

    }

}

